export default defineEventHandler(async (event) => {
  const query = getQuery(event);
  const { address, location, type = 'regeo' } = query;
  
  // 模拟延迟
  await new Promise(resolve => setTimeout(resolve, 300));
  
  try {
    let mockGeocodeData;
    
    if (type === 'regeo' && location) {
      // 逆地理编码：坐标转地址
      mockGeocodeData = {
        success: true,
        data: {
          formatted_address: '广东省广州市天河区珠江新城花城大道',
          addressComponent: {
            country: '中国',
            province: '广东省',
            city: '广州市',
            district: '天河区',
            township: '珠江新城街道',
            neighborhood: '珠江新城',
            street: '花城大道',
            streetNumber: '123号',
            adcode: '440106',
            citycode: '020'
          },
          pois: [
            {
              id: 'B0FFJQ1QJN',
              name: '广州塔',
              type: '风景名胜',
              distance: '500',
              direction: '东北',
              location: '113.289405,23.013125'
            },
            {
              id: 'B0FFJQ1QJO',
              name: '珠江新城地铁站',
              type: '交通设施',
              distance: '800',
              direction: '西南',
              location: '113.287405,23.011125'
            }
          ],
          roads: [
            {
              id: 'B0FFJQ1QJP',
              name: '花城大道',
              direction: '东西',
              distance: '0',
              location: '113.289405,23.013125'
            }
          ]
        },
        message: '地理编码查询成功'
      };
    } else if (type === 'geo' && address) {
      // 地理编码：地址转坐标
      mockGeocodeData = {
        success: true,
        data: [
          {
            country: '中国',
            province: '广东省',
            city: '广州市',
            district: '天河区',
            township: '珠江新城街道',
            street: '花城大道',
            number: '123号',
            adcode: '440106',
            location: '113.289405,23.013125',
            level: '门牌号'
          }
        ],
        message: '地理编码查询成功'
      };
    } else {
      throw createError({
        statusCode: 400,
        statusMessage: '缺少必要参数：location(逆地理编码) 或 address(地理编码)'
      });
    }
    
    return mockGeocodeData;
  } catch (error) {
    console.error('地理编码API模拟数据生成失败:', error);
    throw createError({
      statusCode: 500,
      statusMessage: '地理编码查询失败'
    });
  }
}); 